# -*- coding: utf-8 -*-
"""
Created on Sat Jan 12 08:30:47 2019

@author: kevin
"""

#coding=utf-8
import requests
import time
import cv2
import CVTools
# from flask import Flask, request, jsonify
import json
import http.client,urllib.parse
import json
#
from keys import testURL
#testURL='http://192.168.1.52:8001/imgGenerate'
s = requests



picPath='testpic/person.jpg'
# picPath='testpic/wyf.jpg'
query=CVTools.picpath2base64(picPath)
#print(query[:30])
dataArray= {
	  "query":query,
	  "alienHeadIndex":-1,
      "vegetateIndex":  -1,
      "environmentIndex":  0,
      "alienPetIndex":  -1,
}

#print(query.decode('utf8').encode('utf8')[:30])
#
t1=time.time()
r=s.post(url=testURL,data=dataArray)
print('time cost',time.time()-t1)
print (r.status_code)
print (r.headers['content-type'])
#print (r.encoding)
#print (r.text[:100])
result=json.loads(r.text)
print(result['result_code'])
if int(list(result['result_code'].keys())[0])>=200:
	img=CVTools.base64CV(result['img'])
	print(cv2.imwrite('return.jpg',img))
	des=result['param_dicts']
	print(result)
	for des in des:

		#print(des)
		if des == {}: continue
		print(des['name'],'-',des['descriptions'])

